package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mail.dubbo.mapper.SmsFlashPromotionProductRelationMapper;
import com.mail.dubbo.mapper.SmsFlashPromotionSessionMapper;
import com.mail.model.db.SmsFlashPromotionProductRelation;
import com.mail.model.db.SmsFlashPromotionSession;
import com.mail.model.vo.SmsFlashPromotionSessionTimeVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Set;

/**
 * @author yan
 * @date 2022/06/21 18:51
 **/
@DubboService
public class SmsFlashPromotionSessionApiImpl implements SmsFlashPromotionSessionApi {

    @Autowired
    private SmsFlashPromotionSessionMapper mapper;
    @Autowired
    private SmsFlashPromotionProductRelationMapper relationMapper;

    @Override
    public void create(SmsFlashPromotionSession promotionSession) {
        mapper.insert(promotionSession);
    }

    @Override
    public void delete(Long id) {
        LambdaQueryWrapper<SmsFlashPromotionSession> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SmsFlashPromotionSession::getId, id);
        mapper.delete(queryWrapper);
        LambdaQueryWrapper<SmsFlashPromotionProductRelation> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(SmsFlashPromotionProductRelation::getFlashPromotionSessionId, id);
        relationMapper.delete(queryWrapper1);
       /* LambdaQueryWrapper<SmsFlashPromotionSession> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SmsFlashPromotionSession::getId, id);
        SmsFlashPromotionSession smsFlashPromotionSession = new SmsFlashPromotionSession();
        smsFlashPromotionSession.setStatus(0);
        mapper.update(smsFlashPromotionSession, wrapper);*/
    }

    @Override
    public List<SmsFlashPromotionSession> list() {
        return mapper.selectAll();

    }

    @Override
    public List<SmsFlashPromotionSession> listByIds(List<Long> ids) {
       return mapper.selectBatchIds(ids);
    }

    @Override
    public void updateStatus(Long id, Long status) {
        mapper.updateStatusById(id,status);
    }

    @Override
    public void update(Long id, SmsFlashPromotionSession session) {
        mapper.updateById(session);
    }

    @Override
    public SmsFlashPromotionSession getFlashSession(Long id) {
        return mapper.selectById(id);
    }

    /*@Override
    public List<SmsFlashPromotionSession> selectList(Integer flashPromotionId) {
        LambdaQueryWrapper<SmsFlashPromotionProductRelation> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SmsFlashPromotionProductRelation::getFlashPromotionId, flashPromotionId);
        List<SmsFlashPromotionProductRelation> productRelations = relationMapper.selectList(wrapper);

        for (SmsFlashPromotionProductRelation productRelation : productRelations) {
            productRelation.getFlashPromotionCount()
        }
        List<Integer> flashPromotionSessionId = CollUtil.getFieldValues(productRelations, "flashPromotionCount", Integer.class);
        List<SmsFlashPromotionSession> list = mapper.selectBatchIds(flashPromotionSessionId);
        return list;
    }*/
}
